Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve naming and allow renaming of memory view instances #69

Merged
merged 4 commits into from
Feb 22, 2024

Conversation

planger
Copy link
Contributor

@planger planger commented Feb 19, 2024

What it does

  • Introduces a heading in the memory inspector view showing a title
  • The title is initialized by the webview-main with an index
  • This title is sent via notification to the webview from the webview-main
  • On hover, an edit button next to the title appears
  • Editing can be initiated by clicking the button or double-clicking the title
  • Once edited, the new title is stored in the OptionWidget state
  • The OptionWidget stores the previous title to support canceling the editing
  • As the initial title is set via props, OptionWidget updates the title on prop update

Fixes #61

How to test

  • Open several memory views and observe how the tabs are named Memory 1, Memory 2, etc.
  • The label in the tab and the title in the view should be equal
  • Hover over the title in the memory view and observe how an edit button appears
  • Click the edit button and observe how a input box appears instead of the title
  • Make sure the input button immediately receives focus and selects entire content
  • Make a change in the input, hit escape and observe how the input disappears and the previous title is kept
  • Now double-click the title and observe how again the input with the title appears
  • Make a change and confirm with enter, and observe how the title is updated in the view and in the tab
  • Double-click again and change to another value, but this time click somewhere else to confirm the editing
  • Verify that again the title is updated in the view and in the tab

Review checklist

Reminder for reviewers

* Introduces a heading in the memory inspector view showing a title
* The title is initialized by the webview-main with an index
* This title is sent via notification to the webview from the webview-main
* On hover, an edit button next to the title appears
* Editing can be initiated by clicking the button or double-clicking the title
* Once edited, the new title is stored in the OptionWidget state
* The OptionWidget stores the previous title to support canceling the editing
* As the initial title is set via props, OptionWidget updates the title on prop update

Fixes eclipse-cdt-cloud#61
Copy link
Contributor

@colin-grant-work colin-grant-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels odd that the tab title and the options widget title are initially out of synch:

image

Ended up on a roundabout path to figuring out why it's probably happening, so the main feedback is to fix the synchronization of message handling.

Perhaps we could include the title in the initial configuration - that would save a request. The listener on the webview side is probably where it needs to be, but it would be nice to avoid prop-drilling if we can - I think we can at least avoid muddling state and props in the OptionsWidget.

Comment on lines 216 to 218
protected setTitle(webviewParticipant: WebviewIdMessageParticipant, title: string): void {
this.messenger.sendNotification(setTitleType, webviewParticipant, title);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The machinery to set title from plugin -> webview feels a little heavy: at the moment, it's only used on panel initialization (and may not be working correctly, since in my test, the panel showed the default Memory rather than Memory + Index).

On the other hand I don't actually have a suggestion here - see my next comment.

Copy link
Contributor Author

@planger planger Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it indeed is a bit heavy-weight. But I'm not aware of a mechanism to store state across webview instances other than in the extension "main". However, as you've suggested, I've now put updating the title into the setMemoryViewSettingsType message.

@@ -23,6 +23,7 @@ import { OptionsWidget } from './options-widget';

interface MemoryWidgetProps extends MemoryDisplayConfiguration {
memory?: Memory;
initialTitle: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is a little confusing - it's really just title, since we don't distinguish between initialTitle and later titles.

It might be possible to avoid prop drilling here and set up the logic for handling the title in the OptionsWidget, since that's the only place it's relevant, but see my next comment for a caveat.

Copy link
Contributor Author

@planger planger Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed initialTitle into title according to your suggestion, which makes a lot of sense especially now when we avoid the need for storing the title as a state in the OptionsWidget. 👍

Regarding the prop drilling... I didn't find a great approach to avoid that though. I personally have a slight preference for keeping the handling of messenger events in a central place on both ends (i.e. the App for the webview part) to avoid having handlers of messages from the "outside" scattered throughout all react components, but this is just a personal preference.

One way of avoiding prop drilling might be to pull up the header into its own component and import it in the MemoryWidget directly, or even removing the middle layer MemoryWidget altogether. Grouping prop-values into interfaces may also help to achieve better clarity against an exploding number of props. However, I feel this might be something to attack in a separate PR, wdyt?

Comment on lines 144 to 145
this.setTitle(webviewParticipant, panel.title);
this.setInitialSettings(webviewParticipant);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that both of these lines should be moved into the handler of the readyType notification handler in setWebviewMessageListener. Otherwise, there's no guarantee that the code that sets up the listeners to handle these requests will have run inside the webview - I suspect that that's why I'm seeing just Memory in the webview I created rather than the intended title. This also suggests that we should probably keep all of the message handling centralized in the App class, even if it's a bit inconvenient: that at least provides the guarantee that the messaging is synchronized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent suggestion! Done! 👍

Comment on lines 153 to 154
value={this.state.title}
onChange={this.handleTitleEdit}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be possible to simplify the state handling here (and avoid storing previousTitle) by not storing the state of the input as title and handling its changes. Instead, set the defaultValue to the current title, let the user do what they want, and then only enact the state change in the title field in the confirmEditedTitle method using the ref for the text input.

Then title would always be passed in as props, and the only job of this widget would be calling the updateTitle method when we're sure the user wants a new title.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent suggestion! Done! 👍

@planger
Copy link
Contributor Author

planger commented Feb 21, 2024

@colin-grant-work Thank you very much for your thorough review and your excellent suggestions. I tried to address all your comments. In particular, we now include the title in the initial configuration to save a request and avoid keeping the initialTitle and title as state in the OptionsWidget.

Copy link
Contributor

@colin-grant-work colin-grant-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the changes.

@colin-grant-work colin-grant-work merged commit 02d77b7 into eclipse-cdt-cloud:main Feb 22, 2024
5 checks passed
@planger planger deleted the issues/61 branch February 22, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve naming and allow renaming of memory view instances
3 participants